package com.lzh.db.config;

import org.springframework.boot.autoconfigure.AutoConfigurationImportFilter;
import org.springframework.boot.autoconfigure.AutoConfigurationMetadata;

import java.util.Arrays;
import java.util.List;

/**
 * @author zhehen.lu
 * @date 2025/8/22 11:02
 */
public class LzhDynamicDataSourceFilter implements AutoConfigurationImportFilter {
    private static final List<String> EXCLUDE_AUTO_CONFIGURATION_CLASSES = Arrays.asList("com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration");

    public LzhDynamicDataSourceFilter() {
        // TODO document why this constructor is empty
    }

    @Override
    public boolean[] match(String[] autoConfigurationClasses, AutoConfigurationMetadata autoConfigurationMetadata) {
        boolean[] match = new boolean[autoConfigurationClasses.length];

        for(int i = 0; i < autoConfigurationClasses.length; ++i) {
            if (EXCLUDE_AUTO_CONFIGURATION_CLASSES.contains(autoConfigurationClasses[i])) {
                match[i] = false;
            } else {
                match[i] = true;
            }
        }

        return match;
    }
}